package com.neborosoft.FlyingDog.android.playing.modes;

import android.app.Activity;
import com.neborosoft.FlyingDog.android.gui.adapters.listview.AlbumListAdapter;
import com.neborosoft.FlyingDog.android.gui.adapters.listview.SongsPlayListAdapter;
import com.neborosoft.FlyingDog.logic.database.AudioDataManager;
import com.neborosoft.FlyingDog.logic.database.content.identified.Album;
import com.neborosoft.FlyingDog.logic.search.suggestions.AlbumSuggestionsProvider;
import com.neborosoft.FlyingDog.logic.search.suggestions.SuggestionsProvider;
import com.neborosoft.android.gui.adapters.listview.ViewArrayAdapter;
import com.neborosoft.android.gui.wrappers.ListViewSwitcher;
import com.neborosoft.lib.FlyingDogRuntimeException;
import com.neborosoft.lib.collections.list.NavigationList;
import com.neborosoft.lib.collections.tree.NTree;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 01.12.12
 * Time: 22:22
 * To change this template use File | Settings | File Templates.
 */
public class AlbumsMode extends TreeStructuredPlayingMode {
    private final AudioDataManager audioDataManager = AudioDataManager.getInstance();
    private static final int ALBUMS_LEVEL = 0;
    private static final int SONGS_LEVEL = 1;

    @Override
    protected Class<? extends ViewArrayAdapter> getListViewAdapterClass(int level) {
        switch(level){
            case ALBUMS_LEVEL: return AlbumListAdapter.class;
            case SONGS_LEVEL: return SongsPlayListAdapter.class;
            default: throw new FlyingDogRuntimeException("invalid level request");
        }
    }

    @Override
    protected int getListViewResourceIdForLevel(int level) {
        if(level == 0){
            return Constants.gridViewSwitcherResource;
        }
        else {
            return Constants.listViewSwitcherResource;
        }
    }

    public AlbumsMode(Activity activity, ListViewSwitcher listView, NTree tree) {
        super(activity, listView, tree);
    }

    @Override
    public Object performSearch(String query) {
        NavigationList<Album> albums = audioDataManager.getAlbums(query);
        setNavigationListNotifiers(albums);
        return albums;
    }

    @Override
    protected SuggestionsProvider createSuggestionsProvider() {
        return new AlbumSuggestionsProvider();
    }
}
